package com.book.book.Controller;

import com.book.book.domain.BookType;
import com.book.book.service.BookcategoryService;
import com.book.book.vo.Resultvo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/bookcategory")
public class BookcategoryController {

    @Autowired
    BookcategoryService bookcategoryService;

    @GetMapping("/tree")
    public Resultvo getTree() {
        BookType tree = bookcategoryService.getTree();
        return Resultvo.success("查询成功", tree);
    }

    @PostMapping("/add")
    public Resultvo add(@RequestBody BookType bookType) {
        bookcategoryService.saveOrUpdate(bookType);
        return Resultvo.success("操作成功", null);
    }

    @DeleteMapping("/{booktypeid}")
    public Resultvo del(@PathVariable Integer booktypeid) {
        bookcategoryService.del(booktypeid);
        return Resultvo.success("删除成功", null);
    }

    @GetMapping("/validateBookTypeName")
    public Resultvo validateBookTypeName(@RequestParam(required = true) String booktypename, @RequestParam(required = false) Integer booktypeid) {
        Boolean flag = bookcategoryService.validateBookTypeName(booktypename, booktypeid);
        return Resultvo.success("", flag);
    }
}